package com.example.administrator.jingpingou.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.activeandroid.Model;
import com.example.administrator.jingpingou.R;
import com.example.administrator.jingpingou.bean.MineCollectBean;

import org.xutils.x;

import java.util.List;

/**
 * Created by lenovo on 2016/8/31.
 */
public class MineCollectAdapter extends BaseAdapter {
    private List<MineCollectBean> mData;
    private Context mContext;
//    private List<Model> mData;

    public MineCollectAdapter(List<MineCollectBean> data,Context context){
        mData =data;
        mContext =context;
    }
    @Override
    public int getCount() {
        return mData==null?0:mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder holder;
        if (convertView==null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_activity_collect,null);
            holder = new MyViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder = (MyViewHolder) convertView.getTag();
        }

        MineCollectBean bean = mData.get(position);
        x.image().bind(holder.mImageView,bean.getPic_url());
        holder.mTextViewSale.setText(bean.getDiscount()+" 折");
        holder.mTextViewOldPri.setText(bean.getOrigin_price());
        holder.mTextViewPri.setText(bean.getNow_price());
        holder.mTextViewCon.setText(bean.getTitle());

        return convertView;
    }
    public static class MyViewHolder {
        private ImageView mImageView;
        private TextView mTextViewPri,mTextViewOldPri,mTextViewCon,mTextViewSale;
        public MyViewHolder(View itemView) {
            mImageView = (ImageView) itemView.findViewById(R.id.iv_activity_collect_icon);
            mTextViewCon = (TextView) itemView.findViewById(R.id.tv_activity_collect_content);
            mTextViewOldPri = (TextView) itemView.findViewById(R.id.tv_activity_collectoldpri);
            mTextViewPri = (TextView) itemView.findViewById(R.id.tv_activity_collect_pri);
            mTextViewSale = (TextView) itemView.findViewById(R.id.tv_activity_collect_sale);
        }
    }
}
